package config;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * Class description...
 *
 * @author mvu
 */
public class SimpleProperties {
  private static Properties _properties;
  private String _file;
  private String NOTEBOOK_LAST_UPDATED = "NotebookLastUpdated";
  private String FOLDER_LAST_UPDATED = "LastModified";

  public SimpleProperties() throws IOException {
    _file = "simple";
    FileInputStream in = new FileInputStream(_file);
    _properties = new Properties();
    _properties.load(in);
    in.close();
  }

  public void setLastModified(long time) throws IOException {
    _properties.setProperty(FOLDER_LAST_UPDATED, String.valueOf(time));
    FileOutputStream out = new FileOutputStream(_file);
    _properties.store(out, "---No Comment---");
    out.close();
  }

  public long getLastModified() throws IOException {
    String lastModified = _properties.getProperty(FOLDER_LAST_UPDATED, "0");
    return Long.valueOf(lastModified);
  }

  public static void main(String[] args) throws IOException {
    new SimpleProperties().getLastModified();
  }

  public long getNotebookLastUpdated() {
    String lastModified = _properties.getProperty(NOTEBOOK_LAST_UPDATED, "0");
    return Long.valueOf(lastModified);
  }

  public void setNotebookLastUpdated(long time) {
    _properties.setProperty(NOTEBOOK_LAST_UPDATED, String.valueOf(time));
    FileOutputStream out = null;
    try {
      out = new FileOutputStream(_file);
      _properties.store(out, "---No Comment---");
      out.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
